package leecode

func sumIndicesWithKSetBits(nums []int, k int) int {
	temp := make([]int, 0)
	for i := 0; i < len(nums); i++ {
		if count(i) == k {
			temp = append(temp, i)
		}
	}
	var sum int
	for _, value := range temp {
		sum += nums[value]
	}
	return sum
}

func count(num int) (count int) {
	//判断二进制数有几个1
	for num > 0 {
		num = num & (num - 1)
		count++
	}
	return
}
